<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" href="preview/css/reset.css"/>
    <link rel="stylesheet" href="preview/css/index.css"/>
    <script src="preview/js/jquery.min.js"></script>
    <script src="preview/js/rem.js"></script>
    <script src="preview/js/prefixfree.min.js"></script>
    <script src="preview/js/baseProtocol.js"></script>
    <script src="preview/js/sx.jquery.zySlideStar.js"></script>
    <title>大数据单模块-今日推荐</title>
</head>
<body>
<div class="reco starModule">
    <div class="sxTitle">今日推荐</div>
    <div class="reco-content sxBgBorder">
        <div class="sxCorner"></div>
        <div class="sxCorner"></div>
        <div class="sxCorner"></div>
        <div class="sxCorner"></div>
        <div class="reco-left zy-Slide zy-Slide2"></div>
    </div>
</div>
</body>
<script>
    var code_url,img_url,rec_str,change_timer=null;
    window.onresize = function(){
        getRem(100, 525);
        today_recommend();
        //今日推荐
        var websocket_recommend;
        //最大重连次数
        var max_try_num_jrtj = 10;
        var curr_try_num_jrtj = 0;
        function today_recommend(){
            curr_try_num_jrtj++;
            try{
                websocket_recommend=new WebSocket(ws_url_jrtj);//参数是服务器地址，还有一个参数是自协议可以不写
                websocket_recommend.onopen=function(res){
                    console.log('info ---->> 今日推荐连接成功...');
                    curr_try_num_jrtj = 0;
                };
                websocket_recommend.onmessage=function(msg){
                    var json = JSON.parse(msg.data);
                    var data = json.data;
                    if (data == null || data == undefined || data.length == 0) {
                        console.log("warning ---->> 今日推荐无数据返回...");
                        return;
                    }
                    console.log('info ---->> 今日推荐数据更新了...');
                    $('.today_recomeImg').html('');   //清空resText里面的所有内容
                    rec_str='';
                    $.each(data, function(i, e){
                        var isImgShow=e.f_book_img.indexOf("http");///如果以http开头说明不等于-1，说明不用拼接地址
                        var isCodeShow=e.f_2dimension_code_url.indexOf("http");
                        if(isImgShow==0){
                            img_url=e.f_book_img;////书封地址
                        }else{
                            ///说明不是打头http,要拼接地址
                            img_url='//'+domain_port+e.f_book_img;////书封地址拼接
                        }
                        if(isCodeShow==0){
                            code_url=e.f_2dimension_code_url;////二维码
                        }else{
                            code_url= "http://bdfw.superlib.com:9025/" + e.f_2dimension_code_url;////拼接二维码的链接地址

                        }
                        rec_str+='<li><img class="bcover" src="'+img_url+'" data-total="800" data-title="'+e.f_book_name+'" data-to="'+e.f_read_count+'"/><a title="123"><img src="'+code_url+'" /></a></li>';
                    });
                    $('.reco-left').html('');
                    $('.reco-left').append(rec_str);
                    if(!!change_timer){
                        clearInterval(change_timer);
                    }
                    change_timer=$('.reco-left').zySlide({ speed: 500,type:3,delay: 6000});

                };
                websocket_recommend.onclose=function(e){
                    if (curr_try_num_jrtj <= max_try_num_jrtj) {
                        console.log("warning ---->> 今日推荐连接关闭，6秒后重新连接...");
                        setTimeout(function () {
                            today_recommend();
                        }, 6000);
                    } else {
                        console.log("warning ---->> 今日推荐连接超过最大重连次数，不再重连...");
                    }
                };
                websocket_recommend.onerror = function () {
                    console.log("error ---->> 今日推荐连接发生错误...");
                };
            } catch (e) {
                console.log("error ---->> 今日推荐连接发生错误...");
            }

        }
    }
    window.onload = function(){
        getRem(100, 525);
    }

</script>
</html>